/*
	ADT - Actionscript Developer's Tool
	Copyright (C) 2010-2011  Damon "Drawm" Perron-Laurin
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program.  If not, see http://www.gnu.org/licenses/.
*/
package com.drawm.adt.debugger {
	/**
	 * @author Drawm
	 * 
	 * Tra   Co
	 * Trace Control
	 */
	public class Traco {
		
//		Contain every allowed user
		private static var users          : Array  = [];
//		Define if the console can trace, usefull to stop every message at once
		public static var  traceAllowed    : Boolean = true;
		
//		Trace a message if the user is allowed to trace
//		Will change msg:String for arg... soon
		public static function alert(who:String, msg:String):void{
			if(traceAllowed && isUserAutorised(who))
				trace(who+" say: "+msg);
		}
//		Ask if a single user is allowed to trace
		private static function isUserAutorised(who : String) : Boolean {
			if(users.indexOf(who) == -1)
				return false;
			else 
				return true;
		}
//		Remove a single user from the queue
		public static function removeUser(who : String) : void {
			if(isUserAutorised(who)){
				var index:int = users.indexOf(who);
				users = users.splice(index,index-1);
			}
		}
//		Add a single user to the allowed queue
		public static function addUser(who : String) : void {
			if(!isUserAutorised(who)){
				users.push(who);
			}
		}
//		Add many users to the allowed queue
		public static function addUsers(...users) : void {
			for(var i:String in users){
				addUser(users[i]);
			}
		}
	}
}
